package core;

import gitobject.Branch;
import gitobject.Head;

import java.io.File;

public class JitCheckout {
    public static String branchPath = repository.Repository.getGitDir() + File.separator + "refs" + File.separator
            + "heads";

    public static void checkout(String name) throws Exception {

        File file = new File(branchPath + File.separator + name);

        if (!file.exists()) {
            System.out.print("error: pathspec " + name + " did not match any file(s) known to Jit.");
        } else {
            Branch branch = Branch.deserialize(Branch.branchPath + File.separator + name);
            Head head = Head.deserialize();
            head.setKey(branch.getKey());
            Head.setName(branch.getName());
            head.writeObject();
            System.out.println("切换到分支 " + "'" + head.getBranchName() + "'");
        }
    }
}
